<?php
/*
 * Created on 7 Jan, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

/**
 * Load default stylesheet
 * */
function _theme_gloolsgarden_load_DefaultCSS(&$vars) {
    drupal_add_css(path_to_theme() . '/css/960/960.css');
    drupal_add_css(path_to_theme() . '/css/960/reset.css');
    drupal_add_css(path_to_theme() . '/css/960/fonts.css');
    drupal_add_css(path_to_theme() . '/css/block-layouts.css');
    drupal_add_css(path_to_theme() . '/css/layout.css');
    drupal_add_css(path_to_theme() . '/css/style.css');
    drupal_add_css(path_to_theme() . '/css/dev.css');
}

function _theme_gloolsgarden_load_LayoutCSS(&$vars){
	if (!isset($vars['layout'])) {
		return false;
	}
    
    $layout = $vars['layout'];
    
    if (file_exists(THEME_GG_DIR_CSS . '/layouts/' . $layout.'.layout.css')) {
    	drupal_add_css(path_to_theme() . '/css/layouts/' . $layout.'.layout.css');
    }
}

function _theme_gloolsgarden_process_layout(&$vars){
    
    if ($vars['is_front']) {
        $layout = 'frontpage';
    }else{
    	if (preg_match('/^[a-z]+/', request_path(), $matched)) {
    		$layout = $matched[0];
    	}
    }
    
    $layoutTemplate = dirname(__FILE__) . '/templates/layouts/' . $layout . '.layout.php';
    
    if (file_exists($layoutTemplate)) {
    	$vars['layout'] = $layout;
    }else{
    	$vars['layout'] = 'default';
    }
    
    drupal_alter('layout', $vars['layout']);
}


/**
 * Automatically load node css for node.
 * */
function _theme_gloolsgarden_load_nodeCSS(&$vars){
	if (!empty($vars['node'])) {
        $nodeType = $vars['node']->type;
        
        if (!file_exists(path_to_theme().'/css/nodetypes/'.$nodeType.'.node.css')) {
            drupal_add_css(path_to_theme().'/css/nodetypes/default.node.css');
        } else {
            drupal_add_css(path_to_theme().'/css/nodetypes/'.$nodeType.'.node.css');
        }
    }
}

function _theme_gloolsgarden_load_nodeViewCSS($node, $viewMode){
    if (!empty($vars['node'])) {
        $nodeType = $vars['node']->type;
        
        $nodeViewStyle = path_to_theme().'/css/nodeviews/'.$node->type . '-' . $viewMode . '.nodeview.css';
        
        if (!file_exists($nodeViewStyle)) {
            drupal_add_css(path_to_theme().'/css/nodeviews/default.nodeview.css');
        } else {
            drupal_add_css($nodeViewStyle);
        }
    }
}

function _theme_gloolsgarden_load_layoutJS(&$vars){
    $layout = $vars['layout'];
    
    if (file_exists(dirname(__FILE__).'/js/layouts/'.$layout.'.layout.js')) {
        drupal_add_css(path_to_theme().'/js/layouts/'.$layout.'.layout.js');
    }
}

function _theme_gloolsgarden_show_breadcrumb($breadcrumb){
    if (!is_array($breadcrumb) || 1>count($breadcrumb)) {
        return null;
    }
    $re = '';
    foreach ($breadcrumb as $link) {
        $re .= empty($re) ? $link : '&nbsp;»&nbsp;'.$link;
    }
    return $re;
}